const path = require('path');
const webpack = require('webpack');
const package = require('./package.json');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const moment = require('moment');
const buildVersion = moment().format('YYYY-MM-DD_HH_mm_ss');

module.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/',
        filename: `js/${package.name}[hash].js`
    },
    module: {
        rules:[
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {}
            },
            {
                test: /\.less|.css$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'less-loader',
                ]
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test:/\.js$/,
                exclude: /node_modules/,
                loader: "eslint-loader",
                enforce: "pre",
            },
            {
                test:/\.(png|jpg|gif)$/,
                loader:'url-loader',
                options: {
                    limit: 10 * 1024,
                    esModule: false,
                }
            },
        ]
    },
    plugins: [
        new VueLoaderPlugin(),
        new HtmlWebpackPlugin({
            version: buildVersion,
            filename: 'index.html',
            template: path.join(__dirname, './public/index.html'),
            inject: 'body'
        }),
        new webpack.DefinePlugin({
            BASE_URL: JSON.stringify('http://localhost:9000/')
        })
    ],

}